#include <REGX52.H>
#include "Timer0.h"
#include "Delay.h"
#include "Key.h"
#include "INTRINS.h"
#include "LCD1602.h"
//void Timer0_Init(void){
//	TMOD = 0x01;	//0000 0001
//	TMOD = TMOD&0xF0;	//把TMOD 的低四位置0, 高四位不变
//	TMOD &= 0xF0;
////	TMOD = TMOD|0x01;	//把把TMOD 的最低位 置1, 高四位不变
//	TMOD |= 0x01;
//	TF0 = 0;
//	TR0 = 1;
//	TH0 = 64535/256;
//	TL0 = 64535%256;
//	//中断导通
//	ET0 = 1;	//导通中断
//	EA = 1; 	//导通总中断
//	//设置中断优先级
//	PT0 = 0;	//设置优先级
//}

unsigned char Sec, Min, Hour;

void main(void){
	LCD_Init();
	Timer0_Init();
	LCD_ShowString(1, 1, "Clock:");
	LCD_ShowChar(2, 6, ':');
	LCD_ShowChar(2, 3, ':');
	while(1){
		LCD_ShowNum(2,7, Sec, 2);
		LCD_ShowNum(2,4, Min, 2);
		LCD_ShowNum(2,1, Hour, 2);
	}
}


void Timer0_Rountine() interrupt 1	//中断函数内不要执行耗时太长的函数
{
	static unsigned int T0_Count;
	TL0 = 0x18;		
	TH0 = 0xFC;	
	T0_Count++;
	if(T0_Count>=1000){
		T0_Count = 0;
		Sec++;
		if(Sec>59){
			Sec = 0;
			Min++;
			if(Min>59){
				Hour++;
				Min = 0;
				if(Hour>=24){
					Hour = 0;
				}
			}
		}
			
	}
}

